local options = {
  termguicolors = true,
  ruler = true,
  background = "dark",
  number = true,
  relativenumber = true,
  showcmd = true,
  cursorline = true,
  shortmess = "atI",
  incsearch = true,
  hlsearch = true,
  winminheight = 0,
  ignorecase = true,
  smartcase = true,
  wildmenu = true,
  wildmode = "list:longest,full",
  scrolljump = 5,
  scrolloff = 3,
  foldenable = true,
  gdefault = true,

  encoding = "utf-8",
  fileencoding = "utf-8",
  fileencodings = "utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936",

  expandtab = true,
  autoindent = true,
  fileformat = "unix",

  tabstop = 4,
  softtabstop = 4,
  shiftwidth = 4,

  foldmethod = indent,
  textwidth = 120
}

for k, v in pairs(options) do
  vim.opt[k] = v
end

vim.g.mapleader = ','
vim.g.solarized_termcolors = 256

vim.cmd([[syntax on]])
vim.cmd("set whichwrap=b,s,h,l,<,>,[,]")
vim.cmd([[set clipboard+=unnamedplus]])
-- set global config var
-- vim.api.nvim_set_var('solarized_termcolors', 256)

vim.api.nvim_create_autocmd({"BufNewFile", "BufRead"}, {
  pattern = { "*.yaml", "*.yml", "*.json", "*.ps1", "*.lua", },
  command = [[set tabstop=2 softtabstop=2 shiftwidth=2]]
})

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "vim", "vimrc", },
  command = [[set tabstop=2 softtabstop=2 shiftwidth=2]]
})

vim.api.nvim_create_autocmd({"FileType"}, {
  pattern = {"gitconfig"},
  command = [[set tabstop=4 softtabstop=4 shiftwidth=4]]
})

vim.api.nvim_create_autocmd({"BufNewFile", "BufRead"}, {
  pattern = { "*.py" },
  command = [[set tabstop=4 softtabstop=4 shiftwidth=4]]
})

vim.cmd("nnoremap ; :")
-- vim.api.nvim_set_keymap('n', ';', ':', {
--     silent = true,
--     noremap = true
-- })
-- vim.keymap.set('n', ';', ':', {noremap = true, silent = true})

vim.api.nvim_set_keymap('i', 'HH', '<Home>', {
  silent = true,
  noremap = true
})

vim.api.nvim_set_keymap('i', 'LL', '<End>', {
  silent = true,
  noremap = true
})

-- autocmd BufWinEnter quickfix nnoremap <silent> <buffer>
--   \   q :cclose<cr>:lclose<cr>
-- autocmd BufEnter * if (winnr('$') == 1 && &buftype ==# 'quickfix' ) |
--   \   bd|
--   \   q | endif
vim.api.nvim_create_autocmd("BufWinEnter", {
  pattern = {"quickfix"},
  command = [[nnoremap <silent><buffer>q :cclose<CR>:lclose<CR>]]
})

vim.api.nvim_create_autocmd("BufEnter", {
  pattern = {"*"},
  command = [[if (winnr('$') == 1 && &buftype ==# 'quickfix') | bd | q | endif]]
})
